package com.study.juc.atomics;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;

import java.util.concurrent.atomic.AtomicReference;

/**
 * @program: juc-study
 * @author: jzhou
 * @date: 2022-08-16 15:45
 * @version: 1.0
 * @description: 原子引用类型演示
 **/
public class AtomicReferenceDemo {
	public static void main(String[] args) {
		AtomicReference<User> atomicReference = new AtomicReference<>();
		User zhangsan = new User("zhangsan", 23);
		User lisi = new User("lisi", 24);

		atomicReference.set(zhangsan);

		System.out.println(atomicReference.compareAndSet(zhangsan, lisi) +"\t"+ atomicReference.get().toString());
		System.out.println(atomicReference.compareAndSet(zhangsan, lisi) +"\t"+ atomicReference.get().toString());
	}
}

@Getter
@ToString
@AllArgsConstructor
class User {
	String userName;
	int age;
}